import 'package:flutter/material.dart';
import 'package:kuwo_music/config.dart';

import 'home_index_video_list.dart';

class HomeIndexVideo extends StatefulWidget {
  HomeIndexVideo({Key key}) : super(key: key);

  @override
  _HomeIndexVideoState createState() => _HomeIndexVideoState();
}

class _HomeIndexVideoState extends State<HomeIndexVideo>
    with SingleTickerProviderStateMixin {
  TabController _controller;
  final List<String> _tabValues = [
    '推荐',
    '热舞',
    '儿童',
    'DJ舞曲',
    '广场舞',
    '新歌首发',
    '小视频',
    '影视',
    '相声',
    '翻唱',
    '现场直播',
    '音乐片段',
  ];
  int activeIndex = 0;
  @override
  void initState() {
    super.initState();
    _controller = TabController(vsync: this, length: _tabValues.length);
  }

  @override
  Widget build(BuildContext context) {
    return Column(
      children: [
        TabBar(
          controller: _controller,
          isScrollable: true,
          indicatorColor: Colors.white,
          tabs: _tabValues.asMap().keys.map((int index) {
            _controller.index;
            if (activeIndex == index) {
              return Container(
                alignment: Alignment.center,
                decoration: BoxDecoration(
                    color: Config.MainColor,
                    borderRadius: BorderRadius.circular(30)),
                padding: EdgeInsets.symmetric(horizontal: 10),
                child: Text(
                  _tabValues[index],
                  style: TextStyle(fontWeight: FontWeight.bold),
                ),
              );
            }
            return Container(
              padding: EdgeInsets.symmetric(vertical: 10),
              child: Text(_tabValues[index]),
            );
          }).toList(),
          onTap: (int index) {
            print(index);
            setState(() {
              activeIndex = index;
            });
          },
        ),
        Expanded(
          child: TabBarView(
            controller: _controller,
            children:
                _tabValues.map((e) => new HomeIndexVideoList(type: e)).toList(),
          ),
        )
      ],
    );
  }
}
